import { ref, watch } from 'vue'
import { addClass, removeClass } from '@lhy-assist/utils'

// 是否暗黑模式
const isDark = ref(false)
watch(isDark, () => {
  const htmlEls = document.getElementsByTagName('html')
  if (htmlEls && htmlEls.length) {
    if (isDark.value) {
      addClass(htmlEls[0], 'dark')
    } else {
      removeClass(htmlEls[0], 'dark')
    }
  }
})

export function useTheme() {
  return {
    isDark,
  }
}
